#ifndef COLLECTION_H
#define COLLECTION_H


#include "data_global.h"
#include "abstractdata.h"
#include "metadata.h"
#include "item.h"


#include <abstractmodelitem.h>


#include <QObject>
#include <QMetaType>
#include <QPointer>
#include <QStringList>

#include <QSharedData>
#include <QSharedDataPointer>


class DATASHARED_EXPORT Collection : public AbstractData
{
    Q_OBJECT

    Q_PROPERTY(QString name READ name WRITE setName)

    class Data : public QSharedData
    {
    public:
        Data(){}
        Data(const Data& other) : QSharedData(other)
        {
            name = other.name;
            optionRefs = other.optionRefs;
        }

        QString name;

        MetaDataPtr meta;
        QMap<int, QPointer<Collection> > optionRefs;

    };

public:

    Q_INVOKABLE Collection(QObject *parent = 0);
    Q_INVOKABLE Collection(const QString& name, QObject *parent = 0);
    Collection(const Collection& other);

    QStringList fields() const;

    QString name() const;
    void setName(const QString& name);

    void addField(const QString& fieldName);
    void setField(int index, const QString& fieldName, bool editable = true);
    void removeField(int index);

    virtual QVariant value(int field, int role = Qt::DisplayRole) const;
    virtual void setValue(int field, const QVariant &value);

    virtual QStringList options(int field) const;
    virtual MetaData* metaData() const;


protected slots:

    void resolveRefs();


protected:

    QSharedDataPointer<Data> d;



};


Q_DECLARE_METATYPE(Collection*)


typedef QPointer<Collection> CollectionPtr;


#endif // COLLECTION_H
